package cn.waqwb.bwcar.controller;

import cn.waqwb.bwcar.dto.DataGridResult;
import cn.waqwb.bwcar.dto.QueryDTO;
import cn.waqwb.bwcar.pojo.CarMake;
import cn.waqwb.bwcar.pojo.CarParamType;
import cn.waqwb.bwcar.service.CarParamTypeService;
import cn.waqwb.bwcar.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JokerQ
 * @date 2019/11/21 - 20:52
 */
@RestController
public class CarParamTypeController {
    @Autowired
    private CarParamTypeService carParamTypeService;

    @RequestMapping("/sys/paramtype/list")
    private DataGridResult findCarParamType(QueryDTO queryDTO){
        return carParamTypeService.findByPage(queryDTO);
    }

    @RequestMapping("/sys/paramtype/del")
    private R delCarParamType(@RequestBody List<Integer> ids){
        for (Integer id: ids
             ) {
            carParamTypeService.delCarParamType(id);
        }
        return R.ok();
    }

    @RequestMapping("/sys/paramtype/info/{id}")
    public R findById(@PathVariable("id") Integer id){
        CarParamType byId = carParamTypeService.findById(id);
        return R.ok().put("paramtype",byId);
    }

    @RequestMapping("/sys/paramtype/save")
    public R addCarParamType(@RequestBody CarParamType carParamType){
        int i = carParamTypeService.addCarParamType(carParamType);
        return i>0?R.ok():R.error("添加失败");
    }


    @RequestMapping("/sys/paramtype/update")
    public R updateCarParamType(@RequestBody CarParamType carParamType){
        int i = carParamTypeService.updateCarParamType(carParamType);
        return i>0?R.ok():R.error("修改失败");
    }

}
